package lk.mrt.cse.wihidum.router.processor;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.client.OperationClient;
import org.apache.log4j.Logger;

import javax.xml.namespace.QName;

import lk.mrt.cse.wihidum.util.WSEventingConstants;
import lk.mrt.cse.wihidum.util.WihidumConstants;

public class AdminMessageTraceProcessor
{
    private static final Logger logger = Logger.getLogger(AdminMessageTraceProcessor.class);

    public String process(String adminAddress)
    {
        try
        {
            ServiceClient serviceClient = new ServiceClient();
            EndpointReference targetEPR = new EndpointReference(adminAddress);
            Options options = new Options();
            options.setTo(targetEPR);
            options.setAction("getMessageTrace");
            serviceClient.setOptions(options);

            OMFactory factory = OMAbstractFactory.getOMFactory();
            OMElement messageElement = factory.createOMElement("GetMessageTracesRequest", null);
            OMElement response = serviceClient.sendReceive(messageElement);

            System.out.println(response);
            return response.getText();
        } catch (AxisFault ex)
        {
            logger.error("Error in sending GetTrace message", ex);
            return null;
        }
        catch (NullPointerException ex)
        {
            logger.error("Error in GetTrace message", ex);
            return null;
        }
    }

}
